1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gdk.ContentFormats;
26 
27 private import gdk.c.functions;
28 public  import gdk.c.types;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import glib.StringG;
32 private import glib.c.functions;
33 private import gobject.ObjectG;
34 private import linker.Loader;
35 
36 
37 /**
38  * The `GdkContentFormats` structure is used to advertise and negotiate the
39  * format of content.
40  * 
41  * You will encounter `GdkContentFormats` when interacting with objects
42  * controlling operations that pass data between different widgets, window
43  * or application, like [class@Gdk.Drag], [class@Gdk.Drop],
44  * [class@Gdk.Clipboard] or [class@Gdk.ContentProvider].
45  * 
46  * GDK supports content in 2 forms: `GType` and mime type.
47  * Using `GTypes` is meant only for in-process content transfers. Mime types
48  * are meant to be used for data passing both in-process and out-of-process.
49  * The details of how data is passed is described in the documentation of
50  * the actual implementations. To transform between the two forms,
51  * [class@Gdk.ContentSerializer] and [class@Gdk.ContentDeserializer] are used.
52  * 
53  * A `GdkContentFormats` describes a set of possible formats content can be
54  * exchanged in. It is assumed that this set is ordered. `GTypes` are more
55  * important than mime types. Order between different `GTypes` or mime types
56  * is the order they were added in, most important first. Functions that
57  * care about order, such as [method@Gdk.ContentFormats.union], will describe
58  * in their documentation how they interpret that order, though in general the
59  * order of the first argument is considered the primary order of the result,
60  * followed by the order of further arguments.
61  * 
62  * For debugging purposes, the function [method@Gdk.ContentFormats.to_string]
63  * exists. It will print a comma-separated list of formats from most important
64  * to least important.
65  * 
66  * `GdkContentFormats` is an immutable struct. After creation, you cannot change
67  * the types it represents. Instead, new `GdkContentFormats` have to be created.
68  * The [struct@Gdk.ContentFormatsBuilder] structure is meant to help in this
69  * endeavor.
70  */
71 public class ContentFormats
72 {
73 	/** the main Gtk struct */
74 	protected GdkContentFormats* gdkContentFormats;
75 	protected bool ownedRef;
76 
77 	/** Get the main Gtk struct */
78 	public GdkContentFormats* getContentFormatsStruct(bool transferOwnership = false)
79 	{
80 		if (transferOwnership)
81 			ownedRef = false;
82 		return gdkContentFormats;
83 	}
84 
85 	/** the main Gtk struct as a void* */
86 	protected void* getStruct()
87 	{
88 		return cast(void*)gdkContentFormats;
89 	}
90 
91 	/**
92 	 * Sets our main struct and passes it to the parent class.
93 	 */
94 	public this (GdkContentFormats* gdkContentFormats, bool ownedRef = false)
95 	{
96 		this.gdkContentFormats = gdkContentFormats;
97 		this.ownedRef = ownedRef;
98 	}
99 
100 	~this ()
101 	{
102 		if ( Linker.isLoaded(LIBRARY_GDK[0]) && ownedRef )
103 			gdk_content_formats_unref(gdkContentFormats);
104 	}
105 
106 
107 	/** */
108 	public static GType getType()
109 	{
110 		return gdk_content_formats_get_type();
111 	}
112 
113 	/**
114 	 * Creates a new `GdkContentFormats` from an array of mime types.
115 	 *
116 	 * The mime types must be valid and different from each other or the
117 	 * behavior of the return value is undefined. If you cannot guarantee
118 	 * this, use [struct@Gdk.ContentFormatsBuilder] instead.
119 	 *
120 	 * Params:
121 	 *     mimeTypes = Pointer to an
122 	 *         array of mime types
123 	 *
124 	 * Returns: the new `GdkContentFormats`.
125 	 *
126 	 * Throws: ConstructionException GTK+ fails to create the object.
127 	 */
128 	public this(string[] mimeTypes)
129 	{
130 		auto __p = gdk_content_formats_new(Str.toStringzArray(mimeTypes), cast(uint)mimeTypes.length);
131 
132 		if(__p is null)
133 		{
134 			throw new ConstructionException("null returned by new");
135 		}
136 
137 		this(cast(GdkContentFormats*) __p);
138 	}
139 
140 	/**
141 	 * Creates a new `GdkContentFormats` for a given `GType`.
142 	 *
143 	 * Params:
144 	 *     type = a `GType`
145 	 *
146 	 * Returns: a new `GdkContentFormats`
147 	 *
148 	 * Throws: ConstructionException GTK+ fails to create the object.
149 	 */
150 	public this(GType type)
151 	{
152 		auto __p = gdk_content_formats_new_for_gtype(type);
153 
154 		if(__p is null)
155 		{
156 			throw new ConstructionException("null returned by new_for_gtype");
157 		}
158 
159 		this(cast(GdkContentFormats*) __p);
160 	}
161 
162 	/**
163 	 * Checks if a given `GType` is part of the given @formats.
164 	 *
165 	 * Params:
166 	 *     type = the `GType` to search for
167 	 *
168 	 * Returns: %TRUE if the `GType` was found
169 	 */
170 	public bool containGtype(GType type)
171 	{
172 		return gdk_content_formats_contain_gtype(gdkContentFormats, type) != 0;
173 	}
174 
175 	/**
176 	 * Checks if a given mime type is part of the given @formats.
177 	 *
178 	 * Params:
179 	 *     mimeType = the mime type to search for
180 	 *
181 	 * Returns: %TRUE if the mime_type was found
182 	 */
183 	public bool containMimeType(string mimeType)
184 	{
185 		return gdk_content_formats_contain_mime_type(gdkContentFormats, Str.toStringz(mimeType)) != 0;
186 	}
187 
188 	/**
189 	 * Gets the `GType`s included in @formats.
190 	 *
191 	 * Note that @formats may not contain any `GType`s, in particular when
192 	 * they are empty. In that case %NULL will be returned.
193 	 *
194 	 * Returns: %G_TYPE_INVALID-terminated array of types included in @formats
195 	 */
196 	public GType[] getGtypes()
197 	{
198 		size_t nGtypes;
199 
200 		auto __p = gdk_content_formats_get_gtypes(gdkContentFormats, &nGtypes);
201 
202 		return __p[0 .. nGtypes];
203 	}
204 
205 	/**
206 	 * Gets the mime types included in @formats.
207 	 *
208 	 * Note that @formats may not contain any mime types, in particular
209 	 * when they are empty. In that case %NULL will be returned.
210 	 *
211 	 * Returns: %NULL-terminated array of interned strings of mime types included
212 	 *     in @formats
213 	 */
214 	public string[] getMimeTypes()
215 	{
216 		size_t nMimeTypes;
217 
218 		return Str.toStringArray(gdk_content_formats_get_mime_types(gdkContentFormats, &nMimeTypes));
219 	}
220 
221 	/**
222 	 * Checks if @first and @second have any matching formats.
223 	 *
224 	 * Params:
225 	 *     second = the `GdkContentFormats` to intersect with
226 	 *
227 	 * Returns: %TRUE if a matching format was found.
228 	 */
229 	public bool match(ContentFormats second)
230 	{
231 		return gdk_content_formats_match(gdkContentFormats, (second is null) ? null : second.getContentFormatsStruct()) != 0;
232 	}
233 
234 	/**
235 	 * Finds the first `GType` from @first that is also contained
236 	 * in @second.
237 	 *
238 	 * If no matching `GType` is found, %G_TYPE_INVALID is returned.
239 	 *
240 	 * Params:
241 	 *     second = the `GdkContentFormats` to intersect with
242 	 *
243 	 * Returns: The first common `GType` or %G_TYPE_INVALID if none.
244 	 */
245 	public GType matchGtype(ContentFormats second)
246 	{
247 		return gdk_content_formats_match_gtype(gdkContentFormats, (second is null) ? null : second.getContentFormatsStruct());
248 	}
249 
250 	/**
251 	 * Finds the first mime type from @first that is also contained
252 	 * in @second.
253 	 *
254 	 * If no matching mime type is found, %NULL is returned.
255 	 *
256 	 * Params:
257 	 *     second = the `GdkContentFormats` to intersect with
258 	 *
259 	 * Returns: The first common mime type or %NULL if none
260 	 */
261 	public string matchMimeType(ContentFormats second)
262 	{
263 		return Str.toString(gdk_content_formats_match_mime_type(gdkContentFormats, (second is null) ? null : second.getContentFormatsStruct()));
264 	}
265 
266 	/**
267 	 * Prints the given @formats into a string for human consumption.
268 	 *
269 	 * The result of this function can later be parsed with
270 	 * [func@Gdk.ContentFormats.parse].
271 	 *
272 	 * Params:
273 	 *     string_ = a `GString` to print into
274 	 */
275 	public void print(StringG string_)
276 	{
277 		gdk_content_formats_print(gdkContentFormats, (string_ is null) ? null : string_.getStringGStruct());
278 	}
279 
280 	alias doref = ref_;
281 	/**
282 	 * Increases the reference count of a `GdkContentFormats` by one.
283 	 *
284 	 * Returns: the passed in `GdkContentFormats`.
285 	 */
286 	public ContentFormats ref_()
287 	{
288 		auto __p = gdk_content_formats_ref(gdkContentFormats);
289 
290 		if(__p is null)
291 		{
292 			return null;
293 		}
294 
295 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
296 	}
297 
298 	/**
299 	 * Prints the given @formats into a human-readable string.
300 	 *
301 	 * The resulting string can be parsed with [func@Gdk.ContentFormats.parse].
302 	 *
303 	 * This is a small wrapper around [method@Gdk.ContentFormats.print]
304 	 * to help when debugging.
305 	 *
306 	 * Returns: a new string
307 	 */
308 	public override string toString()
309 	{
310 		auto retStr = gdk_content_formats_to_string(gdkContentFormats);
311 
312 		scope(exit) Str.freeString(retStr);
313 		return Str.toString(retStr);
314 	}
315 
316 	alias unio = union_;
317 	/**
318 	 * Append all missing types from @second to @first, in the order
319 	 * they had in @second.
320 	 *
321 	 * Params:
322 	 *     second = the `GdkContentFormats` to merge from
323 	 *
324 	 * Returns: a new `GdkContentFormats`
325 	 */
326 	public ContentFormats union_(ContentFormats second)
327 	{
328 		auto __p = gdk_content_formats_union(gdkContentFormats, (second is null) ? null : second.getContentFormatsStruct());
329 
330 		if(__p is null)
331 		{
332 			return null;
333 		}
334 
335 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
336 	}
337 
338 	/**
339 	 * Add GTypes for mime types in @formats for which deserializers are
340 	 * registered.
341 	 *
342 	 * Returns: a new `GdkContentFormats`
343 	 */
344 	public ContentFormats unionDeserializeGtypes()
345 	{
346 		auto __p = gdk_content_formats_union_deserialize_gtypes(gdkContentFormats);
347 
348 		if(__p is null)
349 		{
350 			return null;
351 		}
352 
353 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
354 	}
355 
356 	/**
357 	 * Add mime types for GTypes in @formats for which deserializers are
358 	 * registered.
359 	 *
360 	 * Returns: a new `GdkContentFormats`
361 	 */
362 	public ContentFormats unionDeserializeMimeTypes()
363 	{
364 		auto __p = gdk_content_formats_union_deserialize_mime_types(gdkContentFormats);
365 
366 		if(__p is null)
367 		{
368 			return null;
369 		}
370 
371 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
372 	}
373 
374 	/**
375 	 * Add GTypes for the mime types in @formats for which serializers are
376 	 * registered.
377 	 *
378 	 * Returns: a new `GdkContentFormats`
379 	 */
380 	public ContentFormats unionSerializeGtypes()
381 	{
382 		auto __p = gdk_content_formats_union_serialize_gtypes(gdkContentFormats);
383 
384 		if(__p is null)
385 		{
386 			return null;
387 		}
388 
389 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
390 	}
391 
392 	/**
393 	 * Add mime types for GTypes in @formats for which serializers are
394 	 * registered.
395 	 *
396 	 * Returns: a new `GdkContentFormats`
397 	 */
398 	public ContentFormats unionSerializeMimeTypes()
399 	{
400 		auto __p = gdk_content_formats_union_serialize_mime_types(gdkContentFormats);
401 
402 		if(__p is null)
403 		{
404 			return null;
405 		}
406 
407 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
408 	}
409 
410 	/**
411 	 * Decreases the reference count of a `GdkContentFormats` by one.
412 	 *
413 	 * If the resulting reference count is zero, frees the formats.
414 	 */
415 	public void unref()
416 	{
417 		gdk_content_formats_unref(gdkContentFormats);
418 	}
419 
420 	/**
421 	 * Parses the given @string into `GdkContentFormats` and
422 	 * returns the formats.
423 	 *
424 	 * Strings printed via [method@Gdk.ContentFormats.to_string]
425 	 * can be read in again successfully using this function.
426 	 *
427 	 * If @string does not describe valid content formats, %NULL
428 	 * is returned.
429 	 *
430 	 * Params:
431 	 *     string_ = the string to parse
432 	 *
433 	 * Returns: the content formats if @string is valid
434 	 *
435 	 * Since: 4.4
436 	 */
437 	public static ContentFormats parse(string string_)
438 	{
439 		auto __p = gdk_content_formats_parse(Str.toStringz(string_));
440 
441 		if(__p is null)
442 		{
443 			return null;
444 		}
445 
446 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true);
447 	}
448 }